package com.wuming.house.core;

import org.apache.commons.lang.builder.ToStringBuilder;

public class CommonResult<T> {
    /**
     * 是否成功
     */
    private boolean success;
    /**
     * 编码
     */
    private String code;
    /**
     * 消息
     */
    private String message;

    /**
     * 总数
     */
    private int total;
    /**
     * 返回结果
     */
    private T data;

    public static <T> CommonResult<T> createSuccessResult() {
        CommonResult<T> result = new CommonResult<T>();
        result.setSuccess(true);
        return result;
    }

    public static <T> CommonResult<T> createSuccessResult(T data, int total, String message) {
        CommonResult<T> result = new CommonResult<T>();
        result.setSuccess(true);
        result.setCode("200");
        result.setMessage(message);
        result.setData(data);
        result.setTotal(total);
        return result;
    }

    public static <T> CommonResult<T> createSuccessResult(String message) {
        CommonResult<T> result = new CommonResult<T>();
        result.setSuccess(true);
        result.setCode("200");
        result.setMessage(message);
        return result;
    }

    public static <T> CommonResult<T> createFailureResult(String message) {
        CommonResult<T> result = new CommonResult<T>();
        result.setMessage(message);
        return result;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}
